package net.seehealth.healthpad.ui;

import java.util.ArrayList;
import java.util.List;

import net.seehealth.healthpad.Constants;
import net.seehealth.healthpad.R;
import net.seehealth.healthpad.application.adapter.MedicalReportAbnormalAdapter;
import net.seehealth.healthpad.application.adapter.MedicalReportTimeAdapter;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager.LayoutParams;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

/**
 * 
 * @className MedicalReportActivity
 * @author wuhongjie
 * @description 体检报告页面
 * @date 2012-4-13 下午7:50:43
 */
public class MedicalReportActivity extends BaseActivity{
	/** 时间选择项适配器*/
	MedicalReportTimeAdapter mTimeAdapter;
	
	/** 时间文本集合*/
	List<String> mTimeList;
	
	/** 异常情况视图*/
	GridView mAbnormalGridView;
	
	/** 异常情况适配器*/
	private MedicalReportAbnormalAdapter mAbnormalAdapter;
	
	/** 异常情况集合*/
	private List<String> mAbnormalList;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		initData();
		initView();

	}

	/**
	 * 初始化数据
	 */
	private void initData() {

	}

	/**
	 * 初始化视图
	 */
	private void initView() {

		setContentView(R.layout.pop_gridview_medical_report);
		
		LayoutParams p = getWindow().getAttributes();  	// 获取对话框当前的参数值
		p.height = (int) (Constants.Screen.HEIGHT * 1.0);   	// 高度设置为屏幕的1.0
		p.width = (int) (Constants.Screen.WIDTH * 1.0);    // 宽度设置为屏幕的1.0

		// 关闭按钮
		((ImageButton)findViewById(R.id.pop_close_btn)).setOnClickListener(mClickListener);

		// 时间列表
		ListView listView = (ListView)findViewById(R.id.lv_medical_report_time);
		mTimeAdapter = new MedicalReportTimeAdapter(mContext);
		mTimeList = new ArrayList<String>();
		for (int i = 0; i < 5; i++) {
			mTimeList.add("  2011年1月30日");
		}
		mTimeAdapter.setData(mTimeList);
        //为ListView添加适配器  
        listView.setAdapter(mTimeAdapter);
        mTimeAdapter.notifyDataSetChanged();
        
        // 异常情况
        mAbnormalGridView = (GridView)findViewById(R.id.gv_medical_report_abnormal);
        mAbnormalList = new ArrayList<String>();
        for (int i = 0; i < 3; i++) {
        	mAbnormalList.add("脂肪肝");
		}
        mAbnormalAdapter = new MedicalReportAbnormalAdapter(mContext, mAbnormalList);
        mAbnormalGridView.setAdapter(mAbnormalAdapter);
        mAbnormalAdapter.notifyDataSetChanged();
        
        // 表格
		TableLayout table = (TableLayout)findViewById(R.id.tl_medical_report_table);
		for (int m = 0; m < 3; m++) {
			// 表格副标题
 			TableRow subTitle = (TableRow)LayoutInflater.from(mContext).inflate(R.layout.pop_gridview_medical_report_table_subtitle, null);
 			table.addView(subTitle);
 			// 表格内容
 			for (int i = 0; i < 5; i++) {
 				// ！！ 放外部会报错
 				TableRow row = (TableRow)LayoutInflater.from(mContext).inflate(R.layout.pop_gridview_medical_report_table_item, null);
 	 			TextView column1 = (TextView)row.findViewById(R.id.tv_medical_report_table_row_column1);
 	 			TextView column2 = (TextView)row.findViewById(R.id.tv_medical_report_table_row_column2);
 	 			TextView column3 = (TextView)row.findViewById(R.id.tv_medical_report_table_row_column3);
 	 			TextView column4 = (TextView)row.findViewById(R.id.tv_medical_report_table_row_column4);
 	 			column1.setText("体重");
 	 			column2.setText("77.2");
 	 			column3.setText("Kg");
 	 			column4.setText("----");
				if (i % 2 == 1) {
					column1.setBackgroundColor(Color.parseColor("#F2F2F2"));
					column2.setBackgroundColor(Color.parseColor("#F2F2F2"));
					column3.setBackgroundColor(Color.parseColor("#F2F2F2"));
					column4.setBackgroundColor(Color.parseColor("#F2F2F2"));
				}
				if(i == 3){
					column2.setText(Html.fromHtml(getHighStringData("143")));
				}
				if(i == 4){
					column2.setText(Html.fromHtml(getLowStringData("52")));
				}
				table.addView(row);
			}
		}
		
	}
	
	/**
	 * 点击事件
	 */
	View.OnClickListener mClickListener = new View.OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.pop_close_btn:		// 关闭按钮
				finish();
				overridePendingTransition(R.anim.popshow_anim, R.anim.pophidden_anim);
				break;
			default:
				break;
			}
		}
	};
	
	/**
	 * 偏高时文字
	 * @param count
	 * @return
	 */
	private String getHighStringData(String count) {
		return "<font color=#ff1100>" + count + "</font>";
	}
	
	/**
	 * 偏低时文字
	 * @param count
	 * @return
	 */
	private String getLowStringData(String count) {
		return "<font color=#00bb00>" + count + "</font>";
	}
}
